using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;

internal static class Class23
{
	[CompilerGenerated]
	private sealed class Class24
	{
		public string string_0;

		public bool method_0(f__AnonymousType0<Assembly, Type> f__AnonymousType0_0)
		{
			return f__AnonymousType0_0.Prop_1.Namespace == this.string_0 && typeof(DbProviderFactory).IsAssignableFrom(f__AnonymousType0_0.Prop_1);
		}
	}

	private static Hashtable hashtable_0 = Hashtable.Synchronized(new Hashtable(50));

	private static Hashtable hashtable_1 = Hashtable.Synchronized(new Hashtable(50));

	[CompilerGenerated]
	private static Func<Assembly, IEnumerable<Type>> func_0;

	[CompilerGenerated]
	private static Func<Assembly, Type, f__AnonymousType0<Assembly, Type>> func_1;

	[CompilerGenerated]
	private static Func<f__AnonymousType0<Assembly, Type>, Type> func_2;

	[MethodImpl(MethodImplOptions.Synchronized)]
	public static void smethod_0(string string_0, string string_1, string string_2, string string_3, Func<string, string> func_3)
	{
		if (Class23.hashtable_0.ContainsKey(string_0))
		{
			throw new InvalidOperationException(string.Format("配置项 [{0}] 已经注册过了。", string_0));
		}
		Class22 @class = new Class22();
		@class.dbProviderFactory_0 = Class23.smethod_3(string_1);
		@class.string_0 = string_1;
		@class.string_1 = (string_2 ?? string.Empty);
		@class.string_2 = string_3;
		@class.func_0 = func_3;
		Class23.hashtable_0.Add(string_0, @class);
		Type type = @class.dbProviderFactory_0.CreateConnection().GetType();
		Class23.hashtable_1[type] = @class.dbProviderFactory_0;
	}

	public static Class22 smethod_1(string string_0)
	{
		return Class23.hashtable_0[string_0] as Class22;
	}

	public static DbProviderFactory smethod_2(Type type_0)
	{
		return Class23.hashtable_1[type_0] as DbProviderFactory;
	}

	public static DbProviderFactory smethod_3(string string_0)
	{
		if (string.IsNullOrEmpty(string_0))
		{
			throw new ArgumentNullException("providerName");
		}
		DbProviderFactory result;
		try
		{
            //result = DbProviderFactories.GetFactory(string_0);
            switch (string_0)
            {
				case "System.Data.SqlClient":
					result = SqlClientFactory.Instance;
					break;
				case "MySql.Data.MySqlClient":
					result = MySqlClientFactory.Instance;
					break;
				case "System.Data.SQLite":
					result = SqliteFactory.Instance;
					break;
				default:
					result = DbProviderFactories.GetFactory(string_0);
					break;
            }
            
		}
		catch (Exception ex)
		{
			DbProviderFactory dbProviderFactory = Class23.smethod_4(string_0);
			if (dbProviderFactory == null)
			{
				throw;
			}
			result = dbProviderFactory;
		}
		return result;
	}

	private static DbProviderFactory smethod_4(string string_0)
	{
		Class23.Class24 @class = new Class23.Class24();
		@class.string_0 = string_0;
		IEnumerable<Assembly> arg_4C_0 = Class29.smethod_0();
		if (Class23.func_0 == null)
		{
			Class23.func_0 = new Func<Assembly, IEnumerable<Type>>(Class23.smethod_5);
		}
		Func<Assembly, IEnumerable<Type>> arg_4C_1 = Class23.func_0;
		if (Class23.func_1 == null)
		{
			Class23.func_1 = new Func<Assembly, Type, f__AnonymousType0<Assembly, Type>>(Class23.smethod_6);
		}
		var arg_7F_0 = arg_4C_0.SelectMany(arg_4C_1, Class23.func_1).Where(new Func<f__AnonymousType0<Assembly, Type>, bool>(@class.method_0));
		if (Class23.func_2 == null)
		{
			Class23.func_2 = new Func<f__AnonymousType0<Assembly, Type>, Type>(Class23.smethod_7);
		}
		Type type = arg_7F_0.Select(Class23.func_2).FirstOrDefault<Type>();
		if (type == null)
		{
			return null;
		}
		return (DbProviderFactory)type.InvokeMember("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField, null, null, null);
	}

	[CompilerGenerated]
	private static IEnumerable<Type> smethod_5(Assembly assembly_0)
	{
		return assembly_0.GetExportedTypes();
	}

	[CompilerGenerated]
	private static f__AnonymousType0<Assembly, Type> smethod_6(Assembly assembly_0, Type type_0)
	{
		return new f__AnonymousType0<Assembly, Type>
        {
            Prop_2 = assembly_0,
            Prop_1 = type_0
		};
	}

	[CompilerGenerated]
	private static Type smethod_7(f__AnonymousType0<Assembly, Type> f__AnonymousType0_0)
	{
		return f__AnonymousType0_0.Prop_1;
	}
}
